package cn.fanyamin.web.struts;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ExceptionHandler;
import org.apache.struts.config.ExceptionConfig;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * DOCUMENT ME!
 *
 * @author $author$
 * @version $Revision: 1.1.1.1 $
  */
public class BaseExceptionHandler extends ExceptionHandler {
    /**
     * DOCUMENT ME!
     */
    protected final Log logger = LogFactory.getLog(getClass());

    /**
     * DOCUMENT ME!
     *
     * @param ex DOCUMENT ME!
     * @param ae DOCUMENT ME!
     * @param mapping DOCUMENT ME!
     * @param formInstance DOCUMENT ME!
     * @param request DOCUMENT ME!
     * @param response DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     *
     * @throws ServletException DOCUMENT ME!
     */
    public ActionForward execute(Exception ex, ExceptionConfig ae, ActionMapping mapping,
        ActionForm formInstance, HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
        logger.debug("exception happened.", ex);
        logger.debug("exception message: " + ex.getMessage());
        logger.debug("exception localized message: " + ex.getLocalizedMessage());
        
        ex.printStackTrace();

        String excepmsg = ex.getMessage();
        request.setAttribute("exception", ex);
        request.setAttribute("errormsg", excepmsg);
        super.execute(ex, ae, mapping, formInstance, request, response);

        return mapping.findForward("error");
    }
}
